from game import*
from ContinentDictionary import*
from gui import *
import random

#def gamePlay(game):
#    while game.players > 1:

def yourTurn(game, p, drafted):
    newCard = False
    assignments = p.deployTo(game, drafted)#returns a list of of countries as long as drafted for placement
    tempboard = game.getBoard()
    for t in assigmnets:
       placeArmies(game, p.n, t)
       tempboard = game.getBoard()
    while True:
        a = p.isAttacking(game)
        if(a == None):
            break
        (attackT, defendT) = a
        attack(game, attackT, defendT)
        tempboard = game.getBoard()
        if p.n == tempboard[defendT][0]:
            placeArmies(game, p.n, defendT, p.extraMovement(game, attackT, defendT))
            if not newCard:
                p.cardPlus()
                newCard = True
    tempboard = game.getBoard()
    a = p.troopMovement(game)#troopMovement returns a true if the player wishes to move armies from two adjacent owned territories
    if a != None:
        (fromT, toT) = a
            # needs assert that both territories are owned by the same player
            # needs assert that territors are neighbors
        troops = p.extraMovement(game, fromT, toT)
            # needs assert for enough armies to move
        moveArmy(game, p, fromT, toT, troops)
    return 

def getTour(territory, toTake):
    #print 'in ' + territory + ' going to ' + str(toTake)
    tour = []
    if (toTake == []):
        return tour
    for t in toTake:
        if(t in routes[territory]):
            amTaking = toTake[:]
            amTaking.remove(t)
            if(amTaking == []):
                return [[t]]
            #if(amTaking.count <=1):
            #    return[[t]]
            for newTour in getTour(t, amTaking):
                newTour.insert(0, t)
                #print 'new tour ' + str(newTour)
                tour.append(newTour)
    return tour






